const fs = require('fs');
const path = require('path');

// 读取文件
const filePath = path.join(__dirname, 'src/pages/chat/chat.tsx');
let content = fs.readFileSync(filePath, 'utf8');

// 修复useEffect依赖数组中的重复变量
const duplicateVars = ['chatId', 'peerId', 'pushUniqueMessage', 'handleVideoOffer', 'handleVoiceOffer', 'endVideoCall', 'endVoiceCall', 'videoCallId', 'voiceCallId', 'refreshMessages'];

// 移除重复的变量
let uniqueVars = [...new Set(duplicateVars)];

// 替换useEffect依赖数组
const oldPattern = /}, \[chatId, peerId, pushUniqueMessage, handleVideoOffer, handleVoiceOffer, endVideoCall, endVoiceCall, videoCallId, voiceCallId, refreshMessages\]\)/g;
const newPattern = `}, [${uniqueVars.join(', ')}])`;

content = content.replace(oldPattern, newPattern);

// 写回文件
fs.writeFileSync(filePath, content, 'utf8');

console.log('语法错误已修复');
